package cn.gpdi.service;

import cn.gpdi.framework.annotation.FwIsOpenRequest;
import cn.gpdi.framework.dao.CommDAO;
import cn.gpdi.framework.pojo.FwTextTransObject;
import cn.gpdi.framework.util.CommUtil;
import cn.gpdi.framework.util.FileUtil;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.io.IOException;
import java.util.*;

/**
 * Created by 司徒鑫(QQ:156845600) on 2018/4/16.
 */
@Service
public class CommService {
    Logger logger = Logger.getLogger(CommService.class);
    @Autowired
    CommDAO commDAO;


    /**
     * 文件上传
     *
     * @param request
     * @return
     * @throws IOException
     */
    public List uplodaFile(HttpServletRequest request) throws IOException {
        List<Map> mapList = new ArrayList<Map>();
        List<MultipartFile> files = FileUtil.getMultipartFile(request);
        int i = 0;
        for (MultipartFile file : files) {
            String path = "E:/springUpload" + (i++) + file.getOriginalFilename();
            file.transferTo(new File(path));    //写入本地
        }
        return mapList;
    }


    public Map test(FwTextTransObject dto) throws Exception {
        Map tjMap = new HashMap();    //常用写法
        tjMap.put("a", 1);
        return tjMap;
    }

    @FwIsOpenRequest
    public Map login(FwTextTransObject dto) throws Exception {
        CommUtil.getDBTime();
        Thread.sleep(5000);
        dto.getSession().setAttribute("LOGIN", 1);
        Map tjMap = new HashMap();    //常用写法
        tjMap.put("login", 1);
        return tjMap;
    }

}
